package com.wanxi.random;

import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    public static void main(String[] args) {
        Random random = new Random();
        int a = random.nextInt(20);
        System.out.println("随机数为：" + a);
//        死循环
//        键盘输入
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("请输入一个数字");
            int num = scanner.nextInt();
            if (a > num) {
                System.out.println("猜小了");
            } else if (a < num) {
                System.out.println("猜大了");
            } else {
                System.out.println("猜中了，恭喜你");
                break;
            }
        }
    }
}
